package com.wisdom.server.config;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.naming.NacosNamingService;
import com.wisdom.core.exception.RpcException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * @description: <实例化服务端 NacosNamingService>
 * @author: Leo
 * @date:2021-08-21 16:48
 */
@Configuration
@DependsOn
@Slf4j
public class NacosServerConfig {

    @Autowired
    private ServerRpcConfig serverRpcConfig;

    @Bean
    public NacosNamingService nacosNamingService() {
        try {
            NacosNamingService nacosNamingService = new NacosNamingService(serverRpcConfig.getServerAdd());
            log.info("初始化 NacosNamingService 成功");
            return nacosNamingService;
        }catch (NacosException e){
            log.info("NacosNamingService 初始化失败");
            throw new RpcException(e.getErrMsg(),e);
        }
    }


}
